package com.wy.util;

import com.alibaba.fastjson.JSON;
import com.wy.constant.RedisConst;
import com.wy.domain.AreaCity;
import com.wy.domain.AreaCounty;
import com.wy.domain.AreaProvince;

import java.util.List;

public class AreaUtil {
	
	public void setAreaProvince(List<AreaProvince> areaProvinces) throws Exception{
		if(null!=areaProvinces&&areaProvinces.size()>0){
			RedisUtil.getInstance().del(RedisConst.AREA_PROVINCE);
			RedisUtil.getInstance().set(RedisConst.AREA_PROVINCE, JSON.toJSONString(areaProvinces));
			areaProvinces.clear();
		}
	}
	
	public void setAreaCity(Long provinceId,List<AreaCity> areaCitys) throws Exception{
		if(null!=areaCitys&&areaCitys.size()>0){
			String key = RedisConst.AREA_CITY+provinceId;
			RedisUtil.getInstance().del(key);
			RedisUtil.getInstance().set(key, JSON.toJSONString(areaCitys));
			areaCitys.clear();
		}
	}
	
	public void setAreaCounty(Long cityId,List<AreaCounty> areaCountys) throws Exception{
		if(null!=areaCountys&&areaCountys.size()>0){
			String key = RedisConst.AREA_COUNTY+cityId;
			RedisUtil.getInstance().del(key);
			RedisUtil.getInstance().set(key, JSON.toJSONString(areaCountys));
			areaCountys.clear();
		}
	}
	
}